package com.lemon.stock.compose

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.focusModifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.lemon.java.system.Permission
import com.lemon.stock.R

/**
 * 分割线
 */
@Composable
fun ListItemDivider() {
    Divider(
        modifier = Modifier.padding(horizontal = 0.dp, vertical = 0.dp),
        color = Color.Gray.copy(alpha = 0.4F)
    )
}

/**
 * 建设中页面
 * @param onback 后退方法
 */
@Composable
fun ConstructionScreen(onback: () -> Unit){
    Scaffold(
        topBar = {
            TopAppBar(
                title = { Text("精彩即将呈献") },
                elevation = 8.dp,
                navigationIcon = {
                    IconButton(onClick = onback) {
                        Icon(Icons.Filled.ArrowBack, contentDescription = null)
                    }
                }
            )
        }
    ){
        Column(
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally,
            modifier = Modifier.fillMaxSize()
        ) {
            Text(text = "功能持续建设中，敬请期待......")
        }
    }
}

@Composable
fun permissionDialog(msg: String, onDismiss: () -> Unit){
    val context = LocalContext.current
    AlertDialog(
        title={ Text("") },
        modifier = Modifier
            .width(260.dp)
            .padding(top = 10.dp),
        text = {
                Column() {
                    Image(
                        painter = painterResource(R.drawable.ic_img_warning),
                        modifier = Modifier
                            .size(50.dp)
                            .align(Alignment.CenterHorizontally),
                        //contentScale = ContentScale.Crop,
                        contentDescription = null
                    )
                    Spacer(modifier = Modifier.height(5.dp))
                    Text("当前操作需要开通权限：$msg，是否现在去开通这些权限？") //, modifier = Modifier.padding(top = 200.dp)
                }
        },
        buttons = {
            Row(
                modifier = Modifier.padding(bottom = 10.dp)
            ){
                OutlinedButton(
                    modifier = Modifier
                        .weight(1f)
                        .padding(horizontal = 10.dp),
                    onClick = { onDismiss() }
                ) {
                    Text("开通完成")
                }
                OutlinedButton(
                    modifier = Modifier
                        .weight(1f)
                        .padding(end = 10.dp),
                    onClick = {
                        Permission.gotoMiuiPermission(context)
                    }
                ) {
                    Text("去开通")
                }
            }
        },
        onDismissRequest = onDismiss
    )
}